#include <bits/stdc++.h>
using namespace std;
#define N 200005
int a[N];
int main()
{
    int n, c;
    long long ct = 0, an = 1, bn = 1;
    cin>>n>>c;
    for(int i = 1; i <= n; ++i)
        cin>>a[i];
    sort(a + 1, a + n + 1);
    int l = 1, r = 1;
    while(r <= n)
    {
        if(a[r] - a[l] > c)
            l++;
        else if(a[r] - a[l] < c)
            r++;
        else
        {
            r++, l++;
            while(r <= n && a[r] == a[r-1])
            {
                r++;
                an++;
            }
            while(l <= n && a[l] == a[l-1])
            {
                l++;
                bn++;
            }
            ct += an * bn;
            an = bn = 1;
        }
    }
    cout<<ct;
    return 0;
}
